//
//  DDInfoEditViewController.m
//  DingDongZP
//
//  Created by Ray on 16/4/11.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDInfoEditViewController.h"

@interface DDInfoEditViewController ()
<UITableViewDataSource,
UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UITextField *textField;
@end

@implementation DDInfoEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    UIButton *ok = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [ok addTarget:self action:@selector(confirmAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *okItem = [[UIBarButtonItem alloc] initWithCustomView:ok];
    self.navigationItem.rightBarButtonItem = okItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)confirmAction:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
    if (self.editCallback) {
        NSString *result = self.textField.text;
        self.editCallback(result);
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    if (!self.textField) {
        self.textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 200, 44)];
        [cell.contentView addSubview:self.textField];
    }
    self.textField.text = self.editInfo;
    return cell;
    return nil;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
